<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	include("function/letter.class.php");
	
	$search_text = chkstr(trim($_REQUEST['search_text']));
	$classid = chkstr(trim($_REQUEST['classid']));
	$prov = chkstr(trim($_REQUEST['prov']));
	$start_time = chkstr(trim($_REQUEST['start_time']));
	$search_text = chkstr(trim($_REQUEST['search_text']));
	$content = chkstr(trim($_REQUEST['content']));
	$endcity = chkstr(trim($_REQUEST['endcity']));
	$starttime = chkstr(trim($_REQUEST['starttime']));
	$endtime = chkstr(trim($_REQUEST['endtime']));
	$price = chkstr(trim($_REQUEST['price']));
	$power = chkstr(trim($_REQUEST['power']));
	$search = '';
	if($search_text){
	 $search = $search."search_text=".$search_text;
	}
	else{
	$search = $search."search_text=".$search_text;
	}
	
	if($classid){
	 $search = $search."&classid=".$classid;
	}
	if($prov){
	 $search = $search."&prov=".$prov;
	}
	if($start_time){
	 $search = $search."&start_time=".$start_time;
	}
	if($search_text){
	 $search = $search."&search_text=".$search_text;
	}
	if($content){
	 $search = $search."&content=".$content;
	}
	if($endcity){
	 $search = $search."&endcity=".$endcity;
	}
	if($starttime){
	 $search = $search."&starttime=".$starttime;
	}
	if($endtime){
	 $search = $search."&endtime=".$endtime;
	}
	if($price){
	 $search = $search."&price=".$price;
	}
	if($power){
	 $search = $search."&power=".$power;
	}
		function GetFistLetter($table,$field){
	    $py = new str2PY();
	    $sql_active = " select $field from $table  where 1 group by $field ORDER BY CONVERT( $field USING gbk ) COLLATE gbk_chinese_ci ASC  ";
		$res_active = mysql_query($sql_active); 
		$i=0;
		while($arr_active = mysql_fetch_array($res_active)){
		 $result = $py->getInitials(mb_substr($arr_active[$field],0,1,'utf-8'));
		 $arr[$i]['chinese'] = $arr_active[$field];
		 $arr[$i]['pinyin'] = $result;
		 $i++;
		}
		return  $arr;
	}
	
	$pinyin_list = GetFistLetter('kboy_forum_active','active_end_prov');
	$count = count($pinyin_list);
	//计算符合条件的字段总和

function str_count($sql,$str){

 $res = mysql_query($sql);

 $num = mysql_num_rows($res);

 $count = 0;

  if($num>0){

	while($arr=mysql_fetch_array($res)){

	 $count = $count + $arr[$str];

	}

  }

  return $count;

}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>搜索_<?= $web_titles ?></title>
<meta name="Keywords" content="搜索,<?= $web_keywords ?>" />
<meta name="Description" content="<?= $web_description ?>" />
<link rel="stylesheet" href="css/common.css"/>
<link rel="stylesheet" href="css/activity.css"/>
<script type="text/javascript" src="js/baidutongji.js"></script>
<script type="text/javascript" src="js/laydate/laydate.js"></script>
</head>
<body>
    <!--top-bar begin-->
	<? include("_include.top.topbar.php") ?>
    <!--top-bar end-->
    <!--header begin-->
	<? include("_include.top.navbar.php") ?>
    <!--banner begin-->
    <div class="hd-banner2" style="background: url(images/hd_ban_02.jpg) no-repeat center top">
        <div class="searchBox">
            <div class="innerSearch wrapper fn-pr clearfix">
                <div class="searchArea">
                    <div class="sfliter s_place fn-pr">
                        <div class="f">
                            <span class="p"><?php if($prov){ echo $prov;}else{ echo "全国";} ?></span>
                            <span>出发</span>
                        </div>
                        <b class="arrow deploy"></b>
                        <div class="fresult">
                            <div class="hotCity clearfix">
                                <label>热门出发城市</label>
                                <ul class="hotul"><li><a href="active_search.php?<?php echo $search;?>" data-city="全国">全国</a></li><li><a href="active_search.php?<?php echo $search;?>&prov=北京" data-city="北京">北京</a></li></ul>
                            </div>
                            <div class="allCity tabs2">
                                <div class="ac_tab clearfix">
                                    <ul>
									<?php
									foreach($pinyin_list as $key=>$val){
									 if($key==0){ $class=" class='on'";}
									 if($key%4==0){ echo "<li ".$class.">";}
									 echo $val['pinyin'];
									 if($key%4==3 || ($key%4!=3 && ($key==($count-1))) ){ echo "</li>";}
									}
									?>
                                    </ul>
                                </div>
                                <div class="ac_box clearfix">
								 <?php
								 foreach($pinyin_list as $key=>$val){
								  if($key==0){ $on="on";}
								  if($key%4==0){ echo "<div class=\"hb1 tab-panel ".$on."\">";}
								 ?>
									<dl>
										<dt><?php echo $val['pinyin'];?></dt>
										<dd><a href="active_search.php?<?php echo $search;?>&prov=<?php echo $val['chinese'];?>"  data-city="<?php echo $val['chinese'];?>"><?php echo $val['chinese'];?></a></dd>
									</dl>
								<?php 
								 if($key%4==3 || ($key%4!=3 && ($key==($count-1))) ){ echo "</div>";}
								}
								 ?>	
                                </div>
                            </div>
 
                        </div>
                    </div>
					 <form method="get" action="active_search.php?<?php echo $search;?>" class="search_bar">
                    <div class="sfliter s_type fn-pr">
                        <input type="text" class="box" name="start_time" onclick="laydate()" value="<?php echo $start_time;?>" placeholder="行程时间">
                        <b class="arrow deploy"></b>
                    </div>
                   
                        <input type="text" name="search_text" id="searchKeyword" placeholder="请输入目的地、景点等关键词" value="<?php echo $search_text;?>">
                        <input type="submit" value="搜索" id="submit-btn">
                    </form>
                </div>
                <div class="hotkeywords">
                    <label>热门关键词：</label>
                    <ul><li><a href="active_search.php?<?php echo $search;?>&prov=新疆乌拉盖大草原">新疆乌拉盖大草原</a></li><li><a href="active_search.php?<?php echo $search;?>&prov=白洋淀">白洋淀</a></li><li><a href="active_search.php?<?php echo $search;?>&prov=百花山">百花山</a></li><li><a href="active_search.php?<?php echo $search;?>&prov=青海湖">青海湖</a></li></ul>
                </div>
            </div>
        </div>
    </div>
    <!--banner end-->
    <!--活动 begin-->
    <div class="f-item-box np">
        <div class="content">
            <div class="breadcrumb"><a href="index.php">首页</a>&gt;<a href="active_search.php?">活动搜索</a>
                <div class="filterResTag">
                    <ul style="display:none">
                        <li>
                            <a href="#">
                                <span class="n">热门主题：</span>
                                <span class="v">徒步</span>
                                <span class="c"></span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="n">热门主题：</span>
                                <span class="v">徒步</span>
                                <span class="c"></span>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="hdFliter clearfix">
                <div class="tab_hd clearfix">
                    <ul>
                        <li <?php if(!$classid){ echo " class='on'";} ?> ><a href="active_search.php?<?php echo $search;?>">全部活动</a></li>
                        <li <?php if($classid == '135' ){ echo " class='on'";} ?>><a href="active_search.php?classid=135">官网活动</a></li>
                        <li <?php if($classid == '136' ){ echo " class='on'";} ?> ><a href="active_search.php?classid=136">大型活动</a></li>
                        <li <?php if($classid == '137' ){ echo " class='on'";} ?> ><a href="active_search.php?classid=137">分部活动</a></li>
                    </ul>
                </div>
                <div class="fbox_hd fll">
                    <div class="fgroup tab-panel">
                        <dl class="clearfix">
                            <dt>热门主题</dt>
                            <dd>
                                <a href="active_search.php?<?php echo $search;?>" <?php if(!$content){ echo " class='selected'";} ?> >全部</a>
                                <div class="detail">
								 <?php
									$bigclass_sql = "select * from kboy_bigclass where pid=144 order by bigclass_order asc, id asc";
									$bigclass_rows = mysql_query($bigclass_sql);
									while($bigclass_rs = mysql_fetch_array($bigclass_rows)){
									?>
                                    <a href="active_search.php?<?php echo $search;?>&content=<?php echo $bigclass_rs['bigclass_cn'];?>" <?php if($content == $bigclass_rs['bigclass_cn']){ echo " class='selected'";} ?>><?php echo $bigclass_rs['bigclass_cn'];?></a>
									<?php
									}
								   ?>
                                </div>
                            </dd>
                        </dl>
                        <dl class="clearfix">
                            <dt>目的地</dt>
                            <dd>
                                <a href="active_search.php?<?php echo $search;?>" <?php if(!$endcity){ echo " class='selected'";} ?> >全部</a>
                                <div class="detail">
								 <?php
								  $sql = " select * from kboy_forum_active where active_end_city != '' group by active_end_city order by active_top desc,active_order desc, id desc";
								  $res = mysql_query($sql);
								  while($arr=mysql_fetch_array($res)){
								  ?>
								  <a <?php if($endcity ==$arr['active_end_city'] ){ echo " class='selected'";} ?> href="active_search.php?<?php echo $search;?>&endcity=<?php echo $arr['active_end_city'];?>"><?php echo $arr['active_end_city'];?></a>
								  <?php
								  }
								 ?>
                                </div>
                            </dd>
                        </dl>
                        <div class="moreFliterBox fn-none">
                            <dl class="clearfix">
                                <dt>出发日期</dt>
                                <dd>
                                    <a href="active_search.php?<?php echo $search;?>" <?php if(!$starttime){ echo " class='selected'";}?> >全部</a>
                                    <div class="detail">
											<form class="selectSetTime" action="active_search.php?<?php echo $search;?>" method="get">
                                            <input type="text" class="J_Item" name="starttime" placeholder="请选择日期" onclick="laydate()">
                                            <span class="line"></span>
                                            <input type="text" class="J_Item" placeholder="请选择日期" onclick="laydate()">
                                            <input type="submit" class="confirmBtn" name="endtime" value="确定">
                                            </form>
                                    </div>
                                </dd>
                            </dl>
                           
                            <dl class="clearfix">
                                <dt>价格</dt>
                                <dd>
                                    <a <?php if(!$prcie){ echo " class='selected'";}?> href="active_search.php?<?php echo $search;?>" >全部</a>
                                    <div class="detail">
                                        <a href="active_search.php?<?php echo $search;?>&price=0-199">￥0-199</a>
                                        <a href="active_search.php?<?php echo $search;?>&price=200-399">￥200-399</a>
                                        <a href="active_search.php?<?php echo $search;?>&price=400-699">￥400-699</a>
                                        <a href="active_search.php?<?php echo $search;?>&price=700-1499">￥700-1499</a>
                                        <a href="active_search.php?<?php echo $search;?>&price=1500-2999">￥1500-2999</a>
                                        <a href="active_search.php?<?php echo $search;?>&price=3000-4499">￥3000-4499</a>
                                        <a href="active_search.php?<?php echo $search;?>&price=4500以上">4500以上</a>
                                    </div>
                                </dd>
                            </dl>
                            <dl class="clearfix">
                                <dt>活动强度</dt>
                                <dd>
                                    <a href="active_search.php?<?php echo $search;?>" class="selected">全部</a>
                                    <div class="detail">
									<?php
										$bigclass_sql = "select * from kboy_bigclass where pid=149 order by bigclass_order asc, id asc";
										$bigclass_rows = mysql_query($bigclass_sql);
										while($bigclass_rs = mysql_fetch_array($bigclass_rows)){
										?>
                                        <a href="active_search.php?<?php echo $search;?>&power=<?php echo $bigclass_rs['bigclass_cn'];?>"><?php echo $bigclass_rs['bigclass_cn'];?></a>
										<?php
										}
									   ?>
                                    </div>
                                </dd>
                            </dl>
                        </div>
                        <div class="moreFliter">
                            <span class="more"><i></i><a>更多筛选条件</a></span>
                            <span class="del fn-pa"><i></i><a href="active_search.php">清空所选条件</a></span>
                        </div>
                    </div>
                </div>
            </div>
			 <?php
			
								$SQL = " where  active_model = 0 and active_state = 0 ";
								if($classid){
								 $SQL = $SQL." and  active_bigclass=$classid ";
								}
								if($prov){
								$SQL = $SQL." and `active_end_prov` like '%".$prov."%' ";
								}
								if($start_time){
								$SQL = $SQL." and `active_start_time` >= '".$start_time."' ";
								}
								if($search_text){
								$SQL = $SQL." and ( `active_end_prov` like '%".$search_text."%' or `active_end_city` like '%".$search_text."%'  or  `active_jingdian` like '%".$search_text."%' or  `active_title` like '%".$search_text."%' ) ";
								}
								if($content){
								$SQL = $SQL." and ( `active_hd_content` like '%".$content."%'  ) ";
								}
								
								if($endcity){
								$SQL = $SQL." and ( `active_end_city` like '%".$endcity."%'  ) ";
								}
								if($starttime){ 
								$SQL = $SQL." and `active_start_time` >= '".$starttime."' ";
								}
								if($endtime){
								$SQL = $SQL." and `active_start_time` <= '".$endtime."' ";
								}  
								if($power){
								$SQL = $SQL." and ( `active_power` like '%".$power."%'  ) ";
								}  
								if($price){
								 if(isInclude($price,'-') ){
								   $prices = explode('-',$price);
								   $SQL = $SQL." and ( `active_all_money` >= '".$prices[0]."' and   `active_all_money` <= '".$prices[1]."' ) ";
								 }
								 else{
								  $price = intval($price);
								  $SQL = $SQL." and ( `active_all_money` >= '".$price."'  ) ";
								 }
								
								}  

								$pagesize = 10; // 分页数量
								$pageval = chkstr(trim($_REQUEST['page'])); // 获取Page的值
								if($pageval){
									if(!is_numeric($pageval)){
										echo erro("Page Error");
									}
									if($pageval <= 1){
										$pageval = 1;
									}
									$page = ($pageval-1) * $pagesize;
									$page .= ",";
								}else{
									$pageval = 1;
								}
								$order = intval($_GET['order']);
								  if($order==1 || $order == 0 ){
								   $orders = " active_hits desc , ";//点击量排序
								  }
								   if($order==2){
								   $orders = " active_favor desc , ";//好评率排序
								  }
								   if($order==3){
								   $orders = " active_all_money desc , ";//价格排序
								  }
								   if($order==4){
								   $orders = " active_start_time desc , ";//出发时间
								  }
								
								if($SQL != ""){
									$pagesql = "select * from kboy_forum_active  ".$SQL." order by ".$orders."  id desc";
								}else{
									$pagesql = "select * from kboy_forum_active  order by ".$orders."  id desc";
								}

								$pagenum = mysql_num_rows(mysql_query($pagesql)); // 总记录数
			 ?>
            <div class="bd-content">
                <div class="con-pane on">
                    <div class="hd-box nb">
                        <div class="hd-box-l">
                            <div class="hd-top-nav">
                                <ul>
                                    <li <?php if(!intval($_GET['order']) || intval($_GET['order']) =='1'){ echo "class='on'";} ?>><a href="active_search.php?<?php echo $search;?>&order=1">人气排序</a></li>
                                    <li <?php if( intval($_GET['order']) =='2'){ echo "class='on'";} ?> ><a href="active_search.php?<?php echo $search;?>&order=2">好评度排序</a></li>
                                    <li <?php if( intval($_GET['order']) =='3'){ echo "class='on'";} ?>><a href="active_search.php?<?php echo $search;?>&order=3">价格</a></li>
                                    <li <?php if( intval($_GET['order']) =='4'){ echo "class='on'";} ?>><a href="active_search.php?<?php echo $search;?>&order=4">出发时间</a></li>
                                    <div class="hd-total">共计<span><?=$pagenum;?></span>个活动</div>
                                </ul>
                            </div>
                            <div class="hd-bd-content">
                                <div class="hd-bd-list">
						<?php
								$pagecount = ceil($pagenum/$pagesize); // 共分多少页
								if($pageval > $pagecount){
									$pageval = $pagecount;
								}
								
								$news_sql = $pagesql." limit $page $pagesize";
								$news_rows = mysql_query($news_sql);
								$i = 1;
								while($news_rs = mysql_fetch_array($news_rows)){
						?>

                                    <dl class="hd-bd-item">
                                        <dt><a href="activeview.php?newsid=<?=$news_rs['id']?>" target="_blank"><img src="<?php  
                                       			 $news_rss = explode(',',$news_rs['active_pic']);
												if($news_rss){
													echo $news_rss[0];
												}else{
													echo $news_rs['active_pic'];
												}
                                        ?>" width="200" height="200" alt=""/></a></dt>
                                        <dd>
                                            <div class="hd-info">
                                                <h3 class="title"><a href="activeview.php?newsid=<?=$news_rs['id']?>" target="_blank"><?=$news_rs['active_title']?></a></h3>
                                                <div class="editor-inner">
                                                    <span class="editor">领队：<a href="forum_news.php?uid=<?=$news_rs['uid']?>" target="_blank"><?=getUserNickName($news_rs['uid'])?></a></span>
                                                    <span class="date"><?=date('Y-m-d',strtotime($news_rs['active_addtime']))?></span>
                                                    <div class="show-pl">
                                                        <span class="watch"><i></i><?=$news_rs['active_hits']?></span>
                                                        <span class="pl"><i></i><?=getNewsNums("kboy_active_message","newsid=".$news_rs['id']);?></span>
                                                        <span class="good"><i></i><?=getNewsNums("kboy_forum_favorite","newsid=".$news_rs['id']."  group by uid");?></span>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="md-info">
                                                <div class="item">
                                                    <span class="icon point-c"><i></i><em style="width: 124px;"><?=$news_rs['active_start_prov']?>出发</em></span>
                                                    <span class="icon point-q"><i></i>去往<em><?=$news_rs['active_end_prov']?><?=$news_rs['active_end_city']?></em></span>
                                                    <span class="icon fun"><i></i><em><?=$news_rs['active_power']?></em></span>
                                                </div>
                                                <div class="item">
                                                    <span class="icon point-d"><i></i><em><?=$news_rs['active_jingdian']?></em></span>
                                                    <span class="icon time"><i></i><em><?=cutstr($news_rs['active_start_time'],10);?> - <?=cutstr($news_rs['active_end_time'],10);?></em></span>
                                                    <span class="final"><i class="bm">报名（<?php echo  $nums = str_count("select * from  kboy_order where order_tuiactive_content = '' and order_tui_content = '' and aid=".$news_rs['id']."  group by uid","order_num") + $news_rs['active_xianzhi'];?>）</i>/<i>余位（<?php echo ($news_rs['active_people']-$nums);?>）</i></span>
                                                </div>
                                            </div>
                                            <div class="bd-info">
                                                <ul>
                                                    <li class="bd-hd"><a href="javascript:;"><?=getClassName("kboy_bigclass","bigclass_cn","id=".$news_rs['active_bigclass'])?></a></li>
                                                    <li class="bd-pl">好评率：<span><?php echo ($news_rs['active_favor']*100);?>%</span></li>
                                                </ul>
                                            </div>
                                        </dd>
                                    </dl>
						<?php
								}
						?>
									
                                    <div class="clearfix"></div>
                                </div>
						<?php
								if($pagenum > $pagesize){
									echo "<div class=\"pagination\"><ul>";
									$url = "active_search.php?".$search;//当前页面
									pagebar($pagecount, $pageval, 7, $url);
									echo "</ul></div>";
								}
						?>
                            </div>
                        </div>
                        <?php include_once('_include.active.rightbar.php');?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--客户案例-->
    <? //include("_include.active.footbar.php") ?>
    
    <!--foot begin-->
	<? include("_include.bottom.footbar.php") ?>
    <!--foot begin-->
    <!--左侧悬浮 begin-->
	<? include("_include.bottom.leftbar.php") ?>
    <!--左侧悬浮 end-->
    <!--右侧悬浮导航 begin-->
	<? include("_include.bottom.rightbar.php") ?>
    <!--右侧悬浮导航 end-->
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="js/jquery.SuperSlide.2.1.1.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
    <script type="text/javascript" src="js/activity.js"></script>
</body>
</html>

